package ru.ipccenter.jshell.frontend.compiler;

import javax.tools.SimpleJavaFileObject;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.net.URI;


public class MemoryByteCode extends SimpleJavaFileObject {

  private final ByteArrayOutputStream outputStream;
  
  protected MemoryByteCode(String name, Kind kind) {
    
    super(URI.create("memo:///" + name.replace('.', '/') + kind.extension), kind);
    outputStream = new ByteArrayOutputStream();
  }

  byte[] toByteArray() {
    return this.outputStream.toByteArray();
  }
  
  @Override
  public OutputStream openOutputStream() {
    
      return this.outputStream;
  }
}
